package org.example.wikwok.mapper;

import org.apache.ibatis.annotations.Select;
import org.example.wikwok.pojo.Video;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface VideoMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Video record);

    int insertSelective(Video record);

    Video selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Video record);

    int updateByPrimaryKeyWithBLOBs(Video record);

    int updateByPrimaryKey(Video record);

    @Select("""         
            SELECT v.*
          FROM Video v
                   JOIN `Like` l ON v.id = l.videoId
          WHERE l.userId = #{userId};""")
    List<Video> selectlikedvideos(int userId);

    @Select("SELECT * FROM Video WHERE uploaderId = #{uploadId}")
    List<Video> selectByUploaderId(int uploadId);

    //这个目前有点问题
    @Select("SELECT id FROM Video WHERE uploaderId = #{uploaderId} AND title = #{title} AND description = #{description};")
    int selectByUploaderIdAndTitleAndDescription(Integer uploaderid, String title, String description);

    @Select("SELECT * FROM Video ORDER BY id LIMIT 5 OFFSET #{offset};")
    List<Video> selectSome(int offset);

    @Select("SELECT * FROM Video WHERE title LIKE CONCAT('%', #{keyword}, '%') OR description LIKE CONCAT('%', #{keyword}, '%');")
    List<Video> selectByTitleOrDescription(String keyword);
}